package com.susong.anqing.forever.main.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.susong.anqing.forever.model.form.HumanForm;
import com.susong.anqing.forever.model.vo.HumanVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.susong.anqing.forever.main.mapper.HumanMapper;
import com.susong.anqing.forever.model.entity.HumanEntity;
import com.susong.anqing.forever.main.service.HumanService;

import javax.annotation.Resource;

/**
    @Package    com.susong.anqing.forever.main.service.impl
    @author hukai
    @date   2024/3/1 15:31
*/
@Service
public class HumanServiceImpl extends ServiceImpl<HumanMapper, HumanEntity> implements HumanService{

    @Resource
    private HumanMapper humanMapper;

    @Override
    public int insertOne(HumanForm form) {
        HumanEntity entity = new HumanEntity();
        BeanUtils.copyProperties(form, entity);
        return humanMapper.insert(entity);
    }

    @Override
    public HumanVo selectOne(HumanForm form) {
        QueryWrapper<HumanEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("username", form.getUsername());
        HumanEntity entity = humanMapper.selectOne(wrapper);
        HumanVo vo = new HumanVo();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }

    @Override
    public HumanEntity alterHuman(HumanForm form) {
        UpdateWrapper<HumanEntity> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", form.getId());
        HumanEntity entity = new HumanEntity();
        BeanUtils.copyProperties(form, entity);
        humanMapper.updateById(entity);
        return entity;
    }
}
